//点击定位插件
window.onload=function(){
    var rect = document.getElementById("Nav").offsetTop;//元素到body的顶部的高度
    var rect2 = document.getElementById("Delivery").offsetTop;
    var rect3 = document.getElementById("commodityDetails").offsetTop;
    var hi = document.getElementById("Nav").clientHeight+1;
    const Nav = document.getElementById("Nav").getBoundingClientRect();// 元素到屏幕窗口的高度
    //console.log(rect,rect2,rect3);
    if (Nav.top <= 0) {
        document.getElementById("Nav").style.position = "fixed";
        document.getElementById("Nav").style.top = "0";
        document.getElementById("Nav").style.marginTop = 0;
        document.getElementById("Delivery").classList.add("margin");
        if (Nav.top > rect+hi - rect3) {
            document.getElementById("firstAnchor1").children[0].classList.add("active");
            document.getElementById("firstAnchor2").children[0].classList.remove("active");

        } else {
            document.getElementById("firstAnchor2").children[0].classList.add("active");
            document.getElementById("firstAnchor1").children[0].classList.remove("active");
        }
    }
    else {
        document.getElementById("Nav").removeAttribute("style");
        document.getElementById("Delivery").classList.remove("margin");
    }
    window.onscroll = function () {
        scrollTop = document.body.scrollTop+document.documentElement.scrollTop;
        var dd
        if(dd&&document.getElementById("Mask")){
            document.getElementById("Mask").style.top = scrollTop+"px";
        }
        //console.log(scrollTop)
        if (rect <= scrollTop) {
            document.getElementById("Nav").style.position = "fixed";
            document.getElementById("Nav").style.top = "0";
            document.getElementById("Nav").style.marginTop = 0;
            document.getElementById("Delivery").classList.add("margin");
        }
        else {
            document.getElementById("Nav").removeAttribute("style");
            document.getElementById("Delivery").classList.remove("margin");
        }
        if (rect2 <= scrollTop && rect3-hi > scrollTop) {
            document.getElementById("firstAnchor1").children[0].classList.add("active");
            document.getElementById("firstAnchor2").children[0].classList.remove("active");

        } else if (rect3-hi <= scrollTop) {
            document.getElementById("firstAnchor2").children[0].classList.add("active");
            document.getElementById("firstAnchor1").children[0].classList.remove("active");
        } else {
            document.getElementById("firstAnchor1").children[0].classList.add("active");
            document.getElementById("firstAnchor2").children[0].classList.remove("active");
        }
    }
    document.getElementById("firstAnchor1").onclick = function () {
        location.href = "#float1";
        document.getElementById("firstAnchor1").children[0].classList.add("active");
        document.getElementById("firstAnchor2").children[0].classList.remove("active");
    }
    document.getElementById("firstAnchor2").onclick = function () {
        location.href = "#float2";
        document.getElementById("firstAnchor2").children[0].classList.add("active");
        document.getElementById("firstAnchor1").children[0].classList.remove("active");
    }
    //微信提示干扰问题的解决
    var length1 = document.getElementsByTagName("input").length;
    for(var d = 0; d<length1; d++){
        document.getElementsByTagName("input")[d].onfocus = function () {
            dd = false;
            //document.body.scrollTop = document.body.scrollHeight;
        }
    }
    var length2 = document.getElementsByTagName("select").length;
    for(var f = 0; f<length2; f++){
        document.getElementsByTagName("select")[f].onfocus = function () {
            dd = false;
        }
    }

}


